<template>
    <div class="page">
        <div class="page-top">
            <!-- 面包屑 -->
            <Hreadcrumb :hreadcrumbAry="hreadcrumbAry" />
        </div>
        <div class="page-content">
            <a-form-model layout="inline" style="margin-bottom: 20px" :form="form">
                <a-form-model-item label="错误类型">
                    <a-select default-value="全部" style="width: 160px" v-model="form.errorType">
                        <a-select-option value="1">
                            飞迩推销帮帮
                        </a-select-option>
                        <a-select-option value="2">
                            销帮帮推飞迩
                        </a-select-option>
                        <a-select-option value="-1">
                            全部
                        </a-select-option>
                    </a-select>
                </a-form-model-item>
                <a-form-model-item label="重推">
                    <a-select default-value="全部" style="width: 100px" v-model="form.redeal">
                        <a-select-option value="0">
                            未处理
                        </a-select-option>
                        <a-select-option value="1">
                            重推成功
                        </a-select-option>
                        <a-select-option value="2">
                            重推失败
                        </a-select-option>
                        <a-select-option value="-1">
                            全部
                        </a-select-option>
                    </a-select>
                </a-form-model-item>
                <a-form-model-item label="创建时间">
                    <a-range-picker show-time format="YYYY-MM-DD HH:mm:ss" v-model="timeValue" @change="bindTime" />
                </a-form-model-item>
                <a-form-model-item label="飞迩单号">
                    <a-input v-model="form.scsOrder"></a-input>
                </a-form-model-item>
                <a-form-model-item label="金蝶单号">
                    <a-input v-model="form.kdOrder"></a-input>
                </a-form-model-item>
                <a-form-model-item>
                    <a-button type="primary" html-type="submit" @click="onSubmit"> 提交 </a-button>
                    <a-button style="margin-left: 15px" @click="bindReset">
                        重置
                    </a-button>
                </a-form-model-item>
            </a-form-model>
            <a-table :columns="columns" :data-source="data" :loading="loading" :pagination="pagination"
                @change="handleTableChange">
                <span slot="options" slot-scope="text, record">
                    <a-button type="primary" style="margin-right: 15px" :hidden="record.redeal == 1 ? true : false"
                        @click="redealKdLog(record)">重传</a-button>
                </span>
                <span slot="redeal" slot-scope="record">
                    {{record == 1 ? '成功' : record == 2 ? '失败' : '未处理'}}
                </span>
            </a-table>
        </div>
    </div>
</template>
<script>
import Hreadcrumb from "@/components/Hreadcrumb";
import { getKdLogList, redealKdLog } from "@/request/api";
export default {
    data() {
        return {
            loading: false,
            hreadcrumbAry: [
                { name: "首页", path: "/", query: {} },
                { name: "日志管理", path: "", query: {} },
                { name: "分销商-金蝶日志", path: "/FXSKDlog", query: {} },
            ],
            columns: [
                {
                    title: "飞迩单号",
                    dataIndex: "scsOrder",
                    key: "scsOrder",
                    width: '',
                },
                {
                    title: "子订单号",
                    dataIndex: "orderSubNumber",
                    key: "orderSubNumber",
                    width: '',
                },
                {
                    title: "采购入库单",
                    dataIndex: "purchaseReceiptNo",
                    key: "purchaseReceiptNo",
                    width: '',
                },
                {
                    title: "销售出库单",
                    dataIndex: "saleStorehouseNo",
                    key: "saleStorehouseNo",
                    width: '',
                },
                {
                    title: "创建时间",
                    dataIndex: "createTime",
                    key: "createTime",
                    width: '',
                },
                {
                    title: "错误信息",
                    dataIndex: "errorMessage",
                    key: "errorMessage",
                    width: 120,
                },
                {
                    title: "状态",
                    dataIndex: "redeal",
                    key: "redeal",
                    width: '',
                    slots: { title: "状态" },
                    scopedSlots: { customRender: "redeal" },
                },
                {
                    title: "重推",
                    dataIndex: "options",
                    key: "options",
                    width: '',
                    slots: { title: "重推" },
                    scopedSlots: { customRender: "options" },
                },
            ],
            pagination: { current: 1, size: 10 },
            data: [],
            form: {
                errorType: "-1",
                startTime: "",
                endTime: "",
                scsOrder: "",
                kdOrder: "",
                redeal:"-1"
            },
            timeValue: undefined,
            centerData: []
        };
    },
    components: {
        Hreadcrumb,
    },
    created() {
        this.getKdLogList(1, 10)
    },
    methods: {
        async getKdLogList(p, ps) {
            this.loading = true;
            let { startTime, endTime, errorType, scsOrder, kdOrder,redeal } = this.form;
            let params =
                "p=" +
                (p - 1) +
                "&ps=" +
                ps +
                `&errorType=${errorType}&scsOrder=${scsOrder}&kdOrder=${kdOrder}&redeal=${redeal}&startTime=${startTime}&endTime=${endTime}`
            let { data } = await getKdLogList(params);
            console.log(data);
            if (data.success) {
                this.loading = false;
                let pagination = { ...this.pagination };
                pagination.total = data.content.total;
                this.pagination = pagination;
                // data.content.records && data.content.records.map(item=>{
                //     let con = JSON.parse(item.content)
                //     item.subNumber = con.data[0].orderSubNumber
                // })
                this.data = data.content.records;
            } else {
                this.loading = false;
                this.data = [];
            }
        },

        bindTime(date, dateString) {
            console.log(date, dateString);
            this.form.startTime = dateString[0];
            this.form.endTime = dateString[1];
        },
        bindReset() {
            this.form = {
                errorType: "-1",
                startTime: "",
                endTime: "",
                scsOrder: "",
                kdOrder: "",
                redeal:"-1"
            };
            this.timeValue = undefined;
            this.getKdLogList(1, 10);
        },
        onSubmit(e) {
            e.preventDefault();
            console.log(this.form);
            this.getKdLogList(1, 10);
        },
        handleTableChange(pagination) {
            console.log(pagination);
            const pager = { ...this.pagination };
            pager.current = pagination.current;
            this.pagination = pager;
            this.getKdLogList(pager.current, pager.size);
        },
        async redealKdLog(record) {
            let param =
                "id=" +
                record.id +
                "&updateBy="
            let { data } = await redealKdLog(param);
            if (data.success) {
                this.getKdLogList(this.pagination.current,10);
                this.$message.success("操作成功");
            } else {
                this.$message.error(data.content);
            }
        },
    },
};
</script>
<style>
.page-content {
    background-color: #fff;
    padding: 25px;
}
</style>